/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sonatype.mavenbook.weather;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.io.SAXReader;

/**
 *
 * @author JHS-Home
 */
public class YahooParser {
    private static Logger log = Logger.getLogger(YahooParser.class);
    
    public Weather parse(InputStream inputStream) throws Exception{
        Weather weather = new Weather();
        
        log.info("XML READER CREATE");
        SAXReader xmlReader = createXmlReader();
        
        Document doc = xmlReader.read(inputStream);
        
        log.info("XML response parsing");
        
        
        return weather;
        
    }
    private SAXReader createXmlReader(){
        Map<String,String> uris = new HashMap<String, String>();
        uris.put("y", "http://xml.weather.yahoo.com/ns/rss/1.0");
        
        DocumentFactory factory = new DocumentFactory();
        factory.setXPathNamespaceURIs(uris);
        
        SAXReader xmlReader = new SAXReader();
        xmlReader.setDocumentFactory(factory);
        return xmlReader;
    }
}
